package com.itqf.service.impl;

import com.itqf.bean.Bill;
import com.itqf.bean.Param;
import com.itqf.bean.Provider;
import com.itqf.mapper.BillMapper;
import com.itqf.service.BillService;
import com.itqf.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * projectName: SpringMVCTest02
 *
 * @author: 元
 * time: 2021/7/5 0005 20:30
 * description:
 */
@Service
public class BillServiceImpl implements BillService {
    @Autowired
    private BillMapper billMapper;

    @Override
    public ResultVO findProviders() {
        //1.处理参数
        //2.调用数据
        List<Provider> providers = billMapper.queryProviders();
        //处理数据库数据
        ResultVO resultVO = null;
        if (providers != null && providers.size() > 0) {
            resultVO = ResultVO.OK(providers);
        } else {
            resultVO = ResultVO.FAIL("未查询到供应商数据！");
        }
        return resultVO;
    }

    @Override
    public ResultVO findBills() {
        List<Bill> bills = billMapper.queryBill();
        ResultVO resultVO = null;
        if (bills != null && bills.size() > 0) {
            resultVO = ResultVO.OK(bills);
        } else {
            resultVO = ResultVO.FAIL("未查询到本系统下账单数据！");
        }
        return resultVO;
    }

    @Override
    public ResultVO saveBills(Bill bill) {
        int rows = billMapper.insertBill(bill);
        ResultVO resultVO = null;
        if (rows > 0) {
            resultVO = ResultVO.OK("数据插入成功！");
        } else {
            resultVO = ResultVO.FAIL("您的数据插入操作失败！！");
        }
        return resultVO;
    }

    @Override
    public ResultVO updateBills(Bill bill) {
        int rows = billMapper.updateBill(bill);
        ResultVO resultVO = null;
        if (rows > 0) {
            resultVO = ResultVO.OK("数据更新成功！");
        } else {
            resultVO = ResultVO.FAIL("您的更新操作失败！！");
        }
        return resultVO;
    }

    @Override
    public ResultVO infoBills(int id) {
        Bill bill = billMapper.queryById(id);
        ResultVO resultVO = null;
        if (bill != null) {
            resultVO = ResultVO.OK(bill);
        } else {
            resultVO = ResultVO.FAIL("未查询到该订单！！");
        }
        return resultVO;
    }

    @Override
    public ResultVO removeBills(int id) {
        int rows = billMapper.deleteById(id);
        ResultVO resultVO = null;
        if (rows > 0) {
            resultVO = ResultVO.OK("删除数据成功！");
        } else {
            resultVO = ResultVO.FAIL("您的删除操作失败！！");
        }
        return resultVO;
    }

    @Override
    public ResultVO serachBills(Param param) {
        List<Bill> bills = billMapper.queryByParam(param);
        ResultVO resultVO = null;
        if (bills != null && bills.size() > 0) {
            resultVO = ResultVO.OK(bills);
        } else {
            resultVO = ResultVO.FAIL("未查询到该账单！");
        }
        return resultVO;
    }
}